﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ARCam3D.Tuple
{
    public class Vector3D : Tuple3D
    {
        public static Vector3D VectorMul(Vector3D vector1, Vector3D vector2)
        {
            return new Vector3D(vector1).VectorMul(vector2);
        }

        public Vector3D() : base() { }

        public Vector3D(double x, double y, double z) : base(x, y, z) { }

        public Vector3D(Tuple3D tuple) : base(tuple) { }

        public Vector3D(Point3D p1, Point3D p2) : base(p2.x - p1.x, p2.y - p1.y, p2.z - p1.z) { }

        public double Length
        {
            get { return Math.Sqrt(x * x + y * y + z * z); }
        }

        public Vector3D Normalize()
        {
            double length = Length;

            x = x / length;
            y = y / length;
            z = z / length;

            return this;
        }

        public Vector3D Add(Vector3D vector)
        {
            x = x + vector.x;
            y = y + vector.y;
            z = z + vector.z;

            return this;
        }

        public Vector3D VectorMul(Vector3D vector)
        {
            double x = this.y * vector.z - vector.y * this.z;
            double y = this.z * vector.x - vector.z * this.x;
            double z = this.x * vector.y - vector.x * this.y;
            this.x = x;
            this.y = y;
            this.z = z;

            return this;
        }

        public double ScalarMul(Vector3D vector)
        {
            return this.x * vector.x + this.y * vector.y + this.z * vector.z;
        }

        public void Invert()
        {
            this.x = -this.x;
            this.y = -this.y;
            this.z = -this.z;
        }
    }
}
